﻿using UnityEngine;
using System.Collections;
using ProtoBuf;

public class PlayerManager : MonoBehaviour {

	public string monsterPath;

	private Player _player;

	void InitPlayer(){
		StartCoroutine(CreatePlayer());
	}

	IEnumerator CreatePlayer(){
		_player = ProtoBufFileDataUtil.LoadFile<Player>(GameSetting.PLAYER_DATA_PATH);

		if( _player == null ){
			_player = new Player();
		}
		ResourceRequest resource = Resources.LoadAsync(monsterPath + System.IO.Path.DirectorySeparatorChar + _player.monsterName);
		while( !resource.isDone ){
			yield return 0;
		}
		GameObject obj = Instantiate(resource.asset as GameObject);
		obj.transform.SetParent(transform);
		obj.transform.position = new Vector3(0,0,0);

		_player.monster = obj.GetComponent<Monster>();

	}

}
